home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 125 / Computer Shopper CD-ROM Issue 125 (1998-07)(Dennis Publishing).iso / Business / Dazzler / DAZZLER.Z / CMoveAction.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-26  |  5.7 KB  |  282 lines

  1. import java.awt.Event;
  2. import java.awt.Point;
  3. import java.io.DataInputStream;
  4.  
  5. public class CMoveAction extends CDisplayAction {
  6.    final int WAIT = 1;
  7.    final int NOTIFY = 32;
  8.    final int PLAY_COUNT = 1048576;
  9.    final byte FOLLOW_PATH;
  10.    final byte POINT_TO_POINT = 1;
  11.    final byte MOVE_TO = 3;
  12.    protected short m_byType;
  13.    protected int m_nFlags;
  14.    protected CVarOrValue m_nMoveTime = new CVarOrValue();
  15.    protected String m_sMoveObject;
  16.    protected CPolyline m_plPath = new CPolyline();
  17.    protected CVarOrValue m_Base = new CVarOrValue();
  18.    protected CVarOrValue m_Position = new CVarOrValue();
  19.    protected int m_nPlayCount;
  20.    private CDrawObj m_pDrawObj;
  21.    private Point m_ptCurrent;
  22.    private int m_nCurrentPt;
  23.    private int m_nDistance;
  24.    private int m_nStepLength;
  25.    private long m_lStepTime;
  26.    private int m_nBezierPt;
  27.    private int m_nBezierSteps;
  28.    private int m_nLoopCounter;
  29.    private long m_lTimeRemaining;
  30.    private long m_lMoveStartTime;
  31.    private long m_lNextStepTime;
  32.    private double m_dDistanceRemaining;
  33.    private short m_byActualType;
  34.  
  35.    boolean IsActive() {
  36.       return this.m_lStepTime != 0L;
  37.    }
  38.  
  39.    boolean DoAction() {
  40.       this.FreeObject();
  41.       this.m_lMoveStartTime = -1L;
  42.       ((CDisplayAction)this).SetDrawRect(this.m_plPath.GetBoundingRect());
  43.       CDrawObj var1 = Globals.thePresView.AddDrawObject((CIconObject)this, 1538, false);
  44.       String var2 = Utils.InsertVariablesInString(this.m_sMoveObject);
  45.       this.m_pDrawObj = Globals.thePresView.FindDrawObject(var2);
  46.       if (this.m_pDrawObj != null) {
  47.          switch (this.m_byType) {
  48.             case 0:
  49.             case 1:
  50.                if (this.m_plPath.npoints >= 2) {
  51.                   this.m_lStepTime = 1L;
  52.                   this.m_dDistanceRemaining = this.m_plPath.GetPathLength();
  53.                   this.m_lTimeRemaining = (long)(10 * this.m_nMoveTime.GetValue());
  54.                   if (var1 != null) {
  55.                      Globals.theAnimThread.AddAnimObject(var1);
  56.                   }
  57.                } else {
  58.                   System.out.println("Too few points specified for FOLLOW_PATH or POINT_TO_POINT: " + this.m_plPath.npoints);
  59.                }
  60.  
  61.                this.m_byActualType = this.m_byType;
  62.             case 2:
  63.             default:
  64.                break;
  65.             case 3:
  66.                this.m_ptCurrent.x = this.m_pDrawObj.GetDrawRect().x;
  67.                this.m_ptCurrent.y = this.m_pDrawObj.GetDrawRect().y;
  68.                if ((this.m_nFlags & 'ΦÇÇ') == 0) {
  69.                   Point var10000 = this.m_ptCurrent;
  70.                   var10000.x += this.m_pDrawObj.GetDrawRect().width / 2;
  71.                   var10000 = this.m_ptCurrent;
  72.                   var10000.y += this.m_pDrawObj.GetDrawRect().height / 2;
  73.                }
  74.  
  75.                Point var3 = new Point(this.m_Base.GetValue(), this.m_Position.GetValue());
  76.                if (var3 != null && !var3.equals(this.m_ptCurrent)) {
  77.                   if (this.m_nMoveTime.GetValue() == 0) {
  78.                      this.m_pDrawObj.MoveTo(var3, true, (this.m_nFlags & 'ΦÇÇ') != 0);
  79.                      this.m_lStepTime = 0L;
  80.                      if ((this.m_nFlags & 32) != 0) {
  81.                         Event var4 = new Event(Globals.thePresView, 2029, (Object)null);
  82.                         var4.modifiers = 2011;
  83.                         Globals.thePresView.postEvent(var4);
  84.                      }
  85.                   } else {
  86.                      this.m_lStepTime = 1L;
  87.                      this.m_byActualType = 0;
  88.                      this.m_nCurrentPt = 0;
  89.                      int[] var7 = new int[]{this.m_ptCurrent.x, var3.x};
  90.                      int[] var5 = new int[]{this.m_ptCurrent.y, var3.y};
  91.                      this.m_plPath = new CPolyline(var7, var5, 2);
  92.                      this.m_dDistanceRemaining = this.m_plPath.GetPathLength();
  93.                      this.m_lTimeRemaining = (long)(10 * this.m_nMoveTime.GetValue());
  94.                      if (var1 != null) {
  95.                         Globals.theAnimThread.AddAnimObject(var1);
  96.                      }
  97.                   }
  98.                } else {
  99.                   this.m_lStepTime = 0L;
  100.                }
  101.          }
  102.       } else {
  103.          this.m_lStepTime = 0L;
  104.          if ((this.m_nFlags & 32) != 0) {
  105.             Event var6 = new Event(Globals.thePresView, 2029, (Object)null);
  106.             var6.modifiers = 2011;
  107.             Globals.thePresView.postEvent(var6);
  108.          }
  109.       }
  110.  
  111.       return true;
  112.    }
  113.  
  114.    boolean LoadFromFile(DataInputStream var1) {
  115.       this.m_byType = FileLoad.ReadCPlusByte(var1);
  116.       this.m_nFlags = FileLoad.ReadCPlusUInt(var1);
  117.       this.m_sMoveObject = FileLoad.ReadCString(var1);
  118.       this.m_nPlayCount = FileLoad.ReadCPlusInt(var1);
  119.       this.m_nMoveTime.LoadFromFile(var1);
  120.       this.m_plPath.LoadFromFile(var1);
  121.       this.m_Base.LoadFromFile(var1);
  122.       CVarOrValue var2 = new CVarOrValue();
  123.       var2.LoadFromFile(var1);
  124.       this.m_Position.LoadFromFile(var1);
  125.       return super.LoadFromFile(var1);
  126.    }
  127.  
  128.    public CMoveAction() {
  129.       ((CDisplayAction)this).SetZOrder((short)2);
  130.    }
  131.  
  132.    void FreeObject() {
  133.       this.m_pDrawObj = null;
  134.       this.m_ptCurrent = new Point(0, 0);
  135.       this.m_nCurrentPt = 0;
  136.       this.m_nDistance = 0;
  137.       this.m_nStepLength = 0;
  138.       this.m_lStepTime = 0L;
  139.       this.m_nBezierPt = 0;
  140.       this.m_nBezierSteps = 0;
  141.       this.m_nLoopCounter = 0;
  142.       this.m_lTimeRemaining = 0L;
  143.       this.m_lNextStepTime = 0L;
  144.       this.m_dDistanceRemaining = (double)0.0F;
  145.       this.m_byActualType = 0;
  146.    }
  147.  
  148.    boolean DoPointToPoint(long var1) {
  149.       boolean var3 = true;
  150.       this.m_lStepTime = (long)(this.m_nMoveTime.GetValue() * 10 / this.m_plPath.npoints);
  151.       this.m_lNextStepTime = Globals.theAnimThread.GetLoopStartTime() + this.m_lStepTime;
  152.       if (this.m_nCurrentPt < this.m_plPath.npoints) {
  153.          this.m_ptCurrent.x = this.m_plPath.xpoints[this.m_nCurrentPt];
  154.          this.m_ptCurrent.y = this.m_plPath.ypoints[this.m_nCurrentPt];
  155.          this.m_pDrawObj.MoveTo(this.m_ptCurrent, true, (this.m_nFlags & 'ΦÇÇ') != 0);
  156.          ++this.m_nCurrentPt;
  157.       } else {
  158.          ++this.m_nLoopCounter;
  159.          if ((this.m_nFlags & 1048576) != 0 && this.m_nLoopCounter >= this.m_nPlayCount) {
  160.             this.m_lStepTime = 0L;
  161.             if ((this.m_nFlags & 32) != 0) {
  162.                Event var4 = new Event(Globals.thePresView, 2029, (Object)null);
  163.                var4.modifiers = 2011;
  164.                Globals.thePresView.postEvent(var4);
  165.             }
  166.  
  167.             var3 = false;
  168.          } else {
  169.             this.m_nCurrentPt = 0;
  170.             this.m_ptCurrent.x = this.m_plPath.xpoints[this.m_nCurrentPt];
  171.             this.m_ptCurrent.y = this.m_plPath.ypoints[this.m_nCurrentPt];
  172.             this.m_pDrawObj.MoveTo(this.m_ptCurrent, true, (this.m_nFlags & 'ΦÇÇ') != 0);
  173.             ++this.m_nCurrentPt;
  174.          }
  175.       }
  176.  
  177.       return var3;
  178.    }
  179.  
  180.    boolean DoFollowPath(long var1) {
  181.       boolean var3 = true;
  182.       if (var1 == -1L || this.m_lMoveStartTime == -1L) {
  183.          this.m_lMoveStartTime = System.currentTimeMillis();
  184.          var1 = Math.max(var1, 1L);
  185.       }
  186.  
  187.       if (var1 == 0L) {
  188.          var1 = 1L;
  189.       }
  190.  
  191.       int var4 = Math.min(Math.max((int)(this.m_lTimeRemaining / var1), 1), (int)this.m_dDistanceRemaining);
  192.       System.currentTimeMillis();
  193.       if (var4 == 0) {
  194.          var4 = 1;
  195.       }
  196.  
  197.       this.m_nStepLength = Math.max((int)(this.m_dDistanceRemaining / (double)var4), 1);
  198.       System.currentTimeMillis();
  199.       this.m_lStepTime = Math.max(this.m_lTimeRemaining / (long)var4, 1L);
  200.       this.m_lNextStepTime = Globals.theAnimThread.GetLoopStartTime() + this.m_lStepTime;
  201.       this.m_dDistanceRemaining -= (double)this.m_nStepLength;
  202.       this.m_lTimeRemaining = this.m_lMoveStartTime + (long)(this.m_nMoveTime.GetValue() * 10) - System.currentTimeMillis();
  203.       this.m_nDistance += this.m_nStepLength;
  204.       new CPathData();
  205.       CPathData var5 = this.m_plPath.GetPointOnPath(this.m_nDistance, this.m_nCurrentPt, this.m_nBezierPt, this.m_nBezierSteps, this.m_nStepLength);
  206.       this.m_nCurrentPt = var5.nCurrentPt;
  207.       this.m_nDistance = var5.nDistance;
  208.       if ((this.m_nFlags & 1048576) != 0) {
  209.          if (this.m_nPlayCount == 1) {
  210.             if (var5.nCurrentPt >= this.m_plPath.npoints - 1 || var5.bLooped) {
  211.                var5.ptNew.move(this.m_plPath.xpoints[this.m_plPath.npoints - 1], this.m_plPath.ypoints[this.m_plPath.npoints - 1]);
  212.                this.m_lStepTime = 0L;
  213.                if ((this.m_nFlags & 32) != 0) {
  214.                   Event var6 = new Event(Globals.thePresView, 2029, (Object)null);
  215.                   var6.modifiers = 2011;
  216.                   Globals.thePresView.postEvent(var6);
  217.                }
  218.  
  219.                var3 = false;
  220.             }
  221.          } else if (var5.bLooped) {
  222.             ++this.m_nLoopCounter;
  223.             if (this.m_nLoopCounter >= this.m_nPlayCount) {
  224.                var5.ptNew.move(this.m_plPath.xpoints[this.m_plPath.npoints - 1], this.m_plPath.ypoints[this.m_plPath.npoints - 1]);
  225.                this.m_lStepTime = 0L;
  226.                if ((this.m_nFlags & 32) != 0) {
  227.                   Event var7 = new Event(Globals.thePresView, 2029, (Object)null);
  228.                   var7.modifiers = 2011;
  229.                   Globals.thePresView.postEvent(var7);
  230.                }
  231.  
  232.                var3 = false;
  233.             } else {
  234.                this.m_lMoveStartTime = System.currentTimeMillis();
  235.                this.m_dDistanceRemaining = this.m_plPath.GetPathLength() - (double)this.m_nDistance;
  236.                this.m_lTimeRemaining = (long)(10 * this.m_nMoveTime.GetValue());
  237.             }
  238.          }
  239.       } else if (var5.bLooped) {
  240.          this.m_lMoveStartTime = System.currentTimeMillis();
  241.          this.m_dDistanceRemaining = this.m_plPath.GetPathLength() - (double)this.m_nDistance;
  242.          this.m_lTimeRemaining = (long)(10 * this.m_nMoveTime.GetValue());
  243.       }
  244.  
  245.       if (this.m_pDrawObj != null) {
  246.          this.m_pDrawObj.MoveTo(var5.ptNew, false, (this.m_nFlags & 'ΦÇÇ') != 0);
  247.       }
  248.  
  249.       return var3;
  250.    }
  251.  
  252.    boolean DoAnimation(CRect var1, long var2) {
  253.       boolean var4 = this.m_lStepTime != 0L;
  254.       if (this.m_lStepTime != 0L && this.m_lNextStepTime <= System.currentTimeMillis()) {
  255.          switch (this.m_byActualType) {
  256.             case 0:
  257.                var4 = this.DoFollowPath(var2);
  258.                break;
  259.             case 1:
  260.                var4 = this.DoPointToPoint(var2);
  261.                break;
  262.             default:
  263.                System.out.println("Invalid move type requested: " + this.m_byActualType);
  264.          }
  265.       }
  266.  
  267.       return var4;
  268.    }
  269.  
  270.    boolean RequiresWait() {
  271.       return (this.m_nFlags & 1) != 0;
  272.    }
  273.  
  274.    CPolyline GetActualPolyline() {
  275.       return this.m_plPath;
  276.    }
  277.  
  278.    CDrawObj GetMoveObject() {
  279.       return this.m_pDrawObj;
  280.    }
  281. }
  282.